class Queue {
	constructor() {
		this.items = []
	}
	enquene(val) {
		this.items.push(val)
	}
	dequene() {
		return this.items.shift()
	}
	front() {
		return this.items[0]
	}
	isEnpty() {
		return this.items.length === 0
	}
	size() {
		return this.items.length
	}
	toString() {
		return this.items.join('').replace(/,/, '')
	}
}

class PriorityQuenue extends Queue {
	// 优先级 越小 优先级越高
	enquene(element, priprity = 0) {
		let index = this.items.length
		if (index === 0) {
			this.items.unshift([element, priprity])
			return
		}
		for (let i = 0; i < this.items.length; i++) {
			const el = this.items[i]
			if (priprity <= el[1]) {
				index = i
				break
			}
		}
		this.items.splice(index, 0, [element, priprity])
	}
	toString() {
		let str = ''
		this.items.forEach((item) => {
			str += item.join(' ') + '\t\t'
		})

		return str
	}
}
